package com.frinder.demo2;

import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

/**
 * Created by frinder on 2017/7/24.
 */
public class MyWork extends UntypedActor {

    LoggingAdapter logger = Logging.getLogger(getContext().system(), this);

    public enum Msg {
        WORKING, DONE, CLOSE
    }

    @Override
    public void preStart() throws Exception {
        logger.info("myWork starting.");
    }

    @Override
    public void onReceive(Object o) throws Exception {
        Msg msg = (Msg) o;
        switch (msg) {
            case WORKING:
                logger.info("It's working.");
                break;
            case DONE:
                logger.info("The work is done.");
                break;
            case CLOSE:
                logger.info("It's close.");
                getSender().tell(Msg.CLOSE, getSelf());
                getContext().stop(getSelf());
                break;
            default:
                logger.info("No Adapter.");
                break;
        }
    }

    @Override
    public void postStop() throws Exception {
        logger.info("myWork stopping.");
    }
}
